// $codepro.audit.disable lineLength, questionableAssignment
package Model;

import java.io.Serializable;
import java.util.*;

/**
 * Market class determines what items will show up in a Planet's MarketWindow. Items and their prices are determined based
 * on the Planet's tech level, government type, and current state of the planet.
 * @author Tim Kerr
 * @version 1.0 11/16/2012
 */
public class Market implements Serializable{
	
	//private TradeGood[] selling = new TradeGood[10];//array of items being sold on a planet
	/** the trade goods demanded by a planet */
	private TradeGood[] demanded = new TradeGood[10];//array of items demanded on a planet
	/** a map */
	private HashMap<String, Object> map;
	/** the map which houses the planet market's goods */
	private HashMap<String, TradeGood> marketMap = new HashMap<String,TradeGood>();
	/** integers which represent whatever we called them */
	private int techLvl, govType, state;
	/** the list of all possible trade good names */
	private ArrayList<String> tradeGoodStrings;
		
	/**
	 * Market class takes in a Planet object from which it will build a marketplace.
	 * @param techLvl :tech level on a planet
	 * @param govType :government type on a planet
	 * @param state : what state the planet is in
	 */
	public Market(int techLvl, int govType, int state){
		map = new HashMap<String, Object>();
		this.techLvl = techLvl;
		this.govType = govType;
		this.state = state;
		tradeGoodStrings = new ArrayList<String>();//holds an array of strings to be passed to MarketWindow (These are keys used to pull from the HashMap)
	}
	
	/**
	 * Conducts a market transaction where a player buys a good from a planet's marketplace
	 * @param itemKey String: used to find a certain item in the marketMap and shipCargo hashMaps
	 * @param maxCargo int: the max cargo of the player's ship
	 * @param currCargo int: the current number of slots filled in the player's ship
	 * @param playerMoney int:  the player's current balance
	 * @param quantity int: the amount of the item purchased
	 * @param shipCargo HashMap<String,TradeGood>: represents the items stored on the players ship
	 * @return map HashMap : Returns a HashMap to the Controller with updated Player and TradeGood information
	 */
	public Map<String, Object> buyItem(String itemKey, int currCargo, int maxCargo, int playerMoney, int quantity, HashMap<String,TradeGood> shipCargo){
		
		//cannot buy an item if there is no space in player.ship
		//cannot buy an item if it costs is more then player.money
		//cannot buy an item if there is not enough of the item in the market to cover the request (also checks null)
		if((currCargo + quantity < maxCargo) && (marketMap.get(itemKey) != null) && (quantity <= marketMap.get(itemKey).getQuantity()) && (playerMoney > quantity * marketMap.get(itemKey).getBaseCost())){
			
			//take money from player
			playerMoney -= (marketMap.get(itemKey).getBaseCost() * quantity);
			
			//put item in ship
			TradeGood item = marketMap.get(itemKey);
			if(shipCargo.get(itemKey) == null){
				TradeGood newItem = new TradeGood(item.getName(), item.getID(), item.getCategory(), item.getBaseCost(), quantity);//clones item
				shipCargo.put(newItem.getName(), newItem);
			} else {
				TradeGood item2 = shipCargo.get(item.getName());
				item2.setQuantity(item2.getQuantity() + quantity);
				shipCargo.put(item2.getName(), item2);
			}
			currCargo += quantity;//update currCargo
			
			//take item from market
			if (item.getQuantity() - quantity == 0){ //if player bought all of an item
				//remove all of item from market
				marketMap.remove(itemKey);
			} else {
				//subtract quantity from market
				item.setQuantity(item.getQuantity() - quantity);
			}
		}
		
		map.put("Current Cargo", currCargo);//Controller needs to replace the current cargo with 'currCargo' by using 'setCurrCargo' method in the Ship class
		map.put("Player Money", playerMoney);//Controller needs to replace player money with 'playerMoney' with 'setMoney' method in Player class
		map.put("Cargo", shipCargo);//Controller needs to replace the ship's cargo with shipCargo
		return map;
	}//end method buyItem
	
	/**
	 * Conducts a market transaction where a player sells a good from their ship
	 * @param String itemKey used to find a certain item in the marketMap and shipCargo hashMaps
	 * @param shipCargo  HashMap<String,TradeGood>  represents the items stored on the players ship
	 * @param currCargo : current number of cargo slots full in the player ship
	 * @param playerMoney : player's current balance
	 * @param quantity : How many of a particular item the player sells at a time
	 * @return map HashMap: returns a map of data that the controller needs to update in the data's respective classes
	 */
	public Map<String, Object> sellItem(String itemKey, HashMap<String,TradeGood> shipCargo, int currCargo, int playerMoney, int quantity){
		if(shipCargo.get(itemKey) != null){
			if ((shipCargo.get(itemKey).getQuantity() >= quantity)){
				//add money to playerMoney
				playerMoney += (shipCargo.get(itemKey).getBaseCost() * quantity);
				//update currCargo
				currCargo -= quantity;
				
				//add item to market
				TradeGood item = shipCargo.get(itemKey);
				TradeGood newItem = new TradeGood(item.getName(), item.getID(), item.getCategory(), item.getBaseCost(), quantity);//clone item
				if (marketMap.get(itemKey) == null){//none in market already
					marketMap.put(itemKey, newItem);
				} else {
					//set quantity in market
					item = marketMap.get(itemKey);
					item.setQuantity(quantity + item.getQuantity());
				}
				
				//take item from shipCargo
				item = shipCargo.get(itemKey);
				if (item.getQuantity() == quantity){//if player sold all of item
					shipCargo.remove(itemKey);
				} else {
					//fix ship item quantity
					item.setQuantity(item.getQuantity() - quantity);
				}
			}
		}
		map.put("Current Cargo", currCargo);//Controller needs to replace the current cargo with 'currCargo' by using 'setCurrCargo' method in the Ship class
		map.put("Player Money", playerMoney);//Controller needs to replace player money with 'playerMoney' with 'setMoney' method in Player class
		map.put("Player Goods", shipCargo);//Controller needs to replace the cargo array in ship with this 'playerGoods' by using the 'setCargo' method in the Ship class
		return map;
	}
	
	/*
	 * TradeGood Array Locations (To make Whitney's Life Much Easier) (Thank you...)
	 * 0:Water
	 * 1:Furs
	 * 2:Food
	 * 3:Ore
	 * 4:Medicine
	 * 5:Narcotics
	 * 6:Firearms
	 * 7:Robots
	 * 8:Machines
	 * 9:Games
	 */
	/**
	 * Generates items for sale to be displayed by a planet. Items generated depend on tech level. Price is generated based on tech level and state.
	 * @return TradeGood[] of items to be displayed by the GUI for the Planet's MarketWindow
	 */
	public Map<String,TradeGood> generateItemsSold(){
			
		//TradeGoods up for sale on a Planet
		switch(techLvl){
			
			case 1://pre-agricultural (sell furs/natural resources)
				marketMap.put("Water", new TradeGood("Water", 0, 1, calcBuyPrice("Water", 30), calcQuantity()));//water
				marketMap.put("Furs", new TradeGood("Furs", 1, 1, calcBuyPrice("Furs", 250), calcQuantity()));//Furs
				marketMap.put("Food", new TradeGood("Food", 2, 1, calcBuyPrice("Food", 105), calcQuantity()));//Food
				marketMap.put("Ore", new TradeGood("Ore", 3, 1, calcBuyPrice("Ore", 390), calcQuantity()));//Ore
				
				tradeGoodStrings.add("Water");
				tradeGoodStrings.add("Furs");
				tradeGoodStrings.add("Food");
				tradeGoodStrings.add("Ore");
				break;

			case 2://agricultural (sell water, furs, food, games, medicine, drugs, firearms)
				marketMap.put("Water", new TradeGood("Water", 0, 1, calcBuyPrice("Water", 30), calcQuantity()));//water
				marketMap.put("Furs", new TradeGood("Furs", 1, 1, calcBuyPrice("Furs", 250), calcQuantity()));//Furs
				marketMap.put("Food", new TradeGood("Food", 2, 1, calcBuyPrice("Food", 105), calcQuantity()));//Food
				marketMap.put("Games", new TradeGood("Games", 9, 1, calcBuyPrice("Games", 180), calcQuantity()));//Games
				marketMap.put("Medicine", new TradeGood("Medicine", 4, 1, calcBuyPrice("Medicine", 510), calcQuantity()));//Medicine
				marketMap.put("Narcotics", new TradeGood("Narcotics", 5, 1, calcBuyPrice("Narcotics", 2625), calcQuantity()));//Narcotics
				marketMap.put("Firearms", new TradeGood("Firearms", 6, 1, calcBuyPrice("Firearms", 725), calcQuantity()));//Firearms
				
				tradeGoodStrings.add("Water");
				tradeGoodStrings.add("Furs");
				tradeGoodStrings.add("Food");
				tradeGoodStrings.add("Games");
				tradeGoodStrings.add("Medicine");
				tradeGoodStrings.add("Narcotics");
				tradeGoodStrings.add("Firearms");
				break;
			
			case 3://medieval (sell water, food, furs, ore)
				marketMap.put("Water", new TradeGood("Water", 0, 1, calcBuyPrice("Water", 30), calcQuantity()));//water
				marketMap.put("Furs", new TradeGood("Furs", 1, 1, calcBuyPrice("Furs", 250), calcQuantity()));//Furs
				marketMap.put("Food", new TradeGood("Food", 2, 1, calcBuyPrice("Food", 105), calcQuantity()));//Food
				marketMap.put("Ore", new TradeGood("Ore", 3, 1, calcBuyPrice("Ore", 390), calcQuantity()));//Ore
				
				tradeGoodStrings.add("Water");
				tradeGoodStrings.add("Furs");
				tradeGoodStrings.add("Food");
				tradeGoodStrings.add("Ore");
				break;
				
			case 4://renaissance (sell cheap ore, board games, firearms)
				marketMap.put("Ore", new TradeGood("Ore", 3, 1, calcBuyPrice("Ore", 390) - 100, calcQuantity()));//Ore (Buy price -100 because they sell cheap ore)
				marketMap.put("Games", new TradeGood("Games", 9, 1, calcBuyPrice("Games", 180), calcQuantity()));//Games
				marketMap.put("Firearms", new TradeGood("Firearms", 6, 1, calcBuyPrice("Firearms", 725), calcQuantity()));//Firearms
				
				tradeGoodStrings.add("Firearms");
				tradeGoodStrings.add("Games");
				tradeGoodStrings.add("Ore");
				break;
				
			case 5://early industrial (sell machines)
				marketMap.put("Machines", new TradeGood("Machines", 8, 1, calcBuyPrice("Machines", 690), calcQuantity()));//Machines
				
				tradeGoodStrings.add("Machines");
				break;
				
			case 6://industrial (sell everything)
				marketMap.put("Water", new TradeGood("Water", 0, 1, calcBuyPrice("Water", 30), calcQuantity()));//water
				marketMap.put("Furs", new TradeGood("Furs", 1, 1, calcBuyPrice("Furs", 250), calcQuantity()));//Furs
				marketMap.put("Food", new TradeGood("Food", 2, 1, calcBuyPrice("Food", 105), calcQuantity()));//Food
				marketMap.put("Games", new TradeGood("Games", 9, 1, calcBuyPrice("Games", 180), calcQuantity()));//Games
				marketMap.put("Medicine", new TradeGood("Medicine", 4, 1, calcBuyPrice("Medicine", 510), calcQuantity()));//Medicine
				marketMap.put("Narcotics", new TradeGood("Narcotics", 5, 1, calcBuyPrice("Narcotics", 2625), calcQuantity()));//Narcotics
				marketMap.put("Firearms", new TradeGood("Firearms", 6, 1, calcBuyPrice("Firearms", 725), calcQuantity()));//Firearms
				marketMap.put("Robots", new TradeGood("Robots", 7, 1, calcBuyPrice("Robots", 3950), calcQuantity()));//Robot
				marketMap.put("Machines", new TradeGood("Machines", 8, 1, calcBuyPrice("Machines", 690), calcQuantity()));//Machines
				marketMap.put("Ore", new TradeGood("Ore", 3, 1, calcBuyPrice("Ore", 390) - 100, calcQuantity()));//Ore (Buy price -100 because they sell cheap ore)
				
				tradeGoodStrings.add("Water");
				tradeGoodStrings.add("Furs");
				tradeGoodStrings.add("Food");
				tradeGoodStrings.add("Games");
				tradeGoodStrings.add("Medicine");
				tradeGoodStrings.add("Narcotics");
				tradeGoodStrings.add("Firearms");
				tradeGoodStrings.add("Robots");
				tradeGoodStrings.add("Machines");
				tradeGoodStrings.add("Ore");
				break;
				
			case 7://post industrial (rich people, buy natural resources at high price)
				//don't sell anything, only buy
				break;
				
			case 8://hi tech (sell machines/robots cheap. buy natural goods at high price)
				marketMap.put("Robots", new TradeGood("Robots", 7, 1, calcBuyPrice("Robots", 3950) - 1500, calcQuantity()));//Robot (Buy price -1500 because they sell robots cheap)
				marketMap.put("Machines", new TradeGood("Machines", 8, 1, calcBuyPrice("Machines", 690) - 300, calcQuantity()));//Machines (Buy price -300 because they sell machines cheap)
				
				tradeGoodStrings.add("Robots");
				tradeGoodStrings.add("Machines");
				break;
			default:
				break;
		}
		return marketMap;
	}
	
	/**
	 * Generates a list of items demanded on a planet based on a planet's government type, tech level, and state.
	 * @return TradeGood[] of items demanded on the planet
	 */
	public TradeGood[] generateItemsDemanded(){
		
		//TradeGoods the planet is willing to buy from the player
		switch(techLvl){
		
			case 1://pre-agricultural (sell/buy furs/natural resources, like narcotics)
				demanded[0] = new TradeGood("Water", 1, 1, calcSellPrice("Water", 30), calcQuantity());//Water
				demanded[1] = new TradeGood("Furs", 2, 1, calcSellPrice("Furs", 250), calcQuantity());//Furs
				demanded[2] = new TradeGood("Food", 3, 1, calcSellPrice("Food", 105), calcQuantity());//Food
				demanded[3] = new TradeGood("Ore", 4, 1, calcSellPrice("Ore", 390), calcQuantity());//Ore
				demanded[5] = new TradeGood("Narcotics", 3, 1, calcSellPrice("Narcotics", 2625), calcQuantity());//Narcotics
				break;
			
			case 2://agricultural (sell/buy water, furs, food, games, medicine, drugs, firearms)
				demanded[0] = new TradeGood("Water", 1, 1, calcSellPrice("Water", 30), calcQuantity());//Water
				demanded[1] = new TradeGood("Furs", 2, 1, calcSellPrice("Furs", 250), calcQuantity());//Furs
				demanded[2] = new TradeGood("Food", 3, 1, calcSellPrice("Food", 105), calcQuantity());//Food
				demanded[5] = new TradeGood("Narcotics", 3, 1, calcSellPrice("Narcotics", 2625), calcQuantity());//Narcotics
				demanded[9] = new TradeGood("Games", 4, 1, calcSellPrice("Games", 180), calcQuantity());//Games
				demanded[4] = new TradeGood("Medicine", 2, 1, calcSellPrice("Medicine", 510), calcQuantity());//Medicine
				demanded[6] = new TradeGood("Firearms", 4, 1, calcSellPrice("Firearms", 725), calcQuantity());//Firearms
				break;
				
			case 3://medieval (buy everything but machines and robots)
				demanded[0] = new TradeGood("Water", 1, 1, calcSellPrice("Water", 30), calcQuantity());//Water
				demanded[1] = new TradeGood("Furs", 2, 1, calcSellPrice("Furs", 250), calcQuantity());//Furs
				demanded[2] = new TradeGood("Food", 3, 1, calcSellPrice("Food", 105), calcQuantity());//Food
				demanded[5] = new TradeGood("Narcotics", 3, 1, calcSellPrice("Narcotics", 2625), calcQuantity());//Narcotics
				demanded[9] = new TradeGood("Games", 4, 1, calcSellPrice("Games", 180), calcQuantity());//Games
				demanded[4] = new TradeGood("Medicine", 2, 1, calcSellPrice("Medicine", 510), calcQuantity());//Medicine
				demanded[6] = new TradeGood("Firearms", 4, 1, calcSellPrice("Firearms", 725), calcQuantity());//Firearms
				demanded[3] = new TradeGood("Ore", 4, 1, calcSellPrice("Ore", 390), calcQuantity());//Ore
				break;
				
			case 4://renaissance (buy everything but robots)
				demanded[0] = new TradeGood("Water", 1, 1, calcSellPrice("Water", 30), calcQuantity());//Water
				demanded[1] = new TradeGood("Furs", 2, 1, calcSellPrice("Furs", 250), calcQuantity());//Furs
				demanded[2] = new TradeGood("Food", 3, 1, calcSellPrice("Food", 105), calcQuantity());//Food
				demanded[5] = new TradeGood("Narcotics", 3, 1, calcSellPrice("Narcotics", 2625), calcQuantity());//Narcotics
				demanded[9] = new TradeGood("Games", 4, 1, calcSellPrice("Games", 180), calcQuantity());//Games
				demanded[4] = new TradeGood("Medicine", 2, 1, calcSellPrice("Medicine", 510), calcQuantity());//Medicine
				demanded[6] = new TradeGood("Firearms", 4, 1, calcSellPrice("Firearms", 725), calcQuantity());//Firearms
				demanded[3] = new TradeGood("Ore", 4, 1, calcSellPrice("Ore", 390), calcQuantity());//Ore
				demanded[8] = new TradeGood("Machines", 4, 1, calcSellPrice("Machines", 690), calcQuantity());//Machines
				break;
				
			case 5://early industrial (sell/buy machines and natural resources. love buying robots)				
				demanded[0] = new TradeGood("Water", 1, 1, calcSellPrice("Water", 30), calcQuantity());//Water
				demanded[1] = new TradeGood("Furs", 2, 1, calcSellPrice("Furs", 250), calcQuantity());//Furs
				demanded[2] = new TradeGood("Food", 3, 1, calcSellPrice("Food", 105), calcQuantity());//Food				
				demanded[8] = new TradeGood("Machines", 4, 1, calcSellPrice("Machines", 690), calcQuantity());//Machines
				demanded[7] = new TradeGood("Robots", 4, 1, calcSellPrice("Robots", 3950), calcQuantity());//Robot
				demanded[3] = new TradeGood("Ore", 4, 1, calcSellPrice("Ore", 390), calcQuantity());//Ore
				break;
				
			case 6://industrial (buy everything)
				demanded[0] = new TradeGood("Water", 1, 1, calcSellPrice("Water", 30), calcQuantity());//Water
				demanded[1] = new TradeGood("Furs", 2, 1, calcSellPrice("Furs", 250), calcQuantity());//Furs
				demanded[2] = new TradeGood("Food", 3, 1, calcSellPrice("Food", 105), calcQuantity());//Food
				demanded[5] = new TradeGood("Narcotics", 3, 1, calcSellPrice("Narcotics", 2625), calcQuantity());//Narcotics
				demanded[9] = new TradeGood("Games", 4, 1, calcSellPrice("Games", 180), calcQuantity());//Games
				demanded[4] = new TradeGood("Medicine", 2, 1, calcSellPrice("Medicine", 510), calcQuantity());//Medicine
				demanded[6] = new TradeGood("Firearms", 4, 1, calcSellPrice("Firearms", 725), calcQuantity());//Firearms
				demanded[3] = new TradeGood("Ore", 4, 1, calcSellPrice("Ore", 390), calcQuantity());//Ore
				demanded[8] = new TradeGood("Machines", 4, 1, calcSellPrice("Machines", 690), calcQuantity());//Machines
				demanded[7] = new TradeGood("Robots", 4, 1, calcSellPrice("Robots", 3950), calcQuantity());//Robot
				break;
				
			case 7://post industrial (rich people, buy natural resources at high price)
				demanded[0] = new TradeGood("Water", 1, 1, calcSellPrice("Water", 30), calcQuantity());//Water
				demanded[1] = new TradeGood("Furs", 2, 1, calcSellPrice("Furs", 250), calcQuantity());//Furs
				demanded[2] = new TradeGood("Food", 3, 1, calcSellPrice("Food", 105), calcQuantity());//Food
				demanded[5] = new TradeGood("Narcotics", 3, 1, calcSellPrice("Narcotics", 2625), calcQuantity());//Narcotics
				demanded[9] = new TradeGood("Games", 4, 1, calcSellPrice("Games", 180), calcQuantity());//Games
				demanded[4] = new TradeGood("Medicine", 2, 1, calcSellPrice("Medicine", 510), calcQuantity());//Medicine
				demanded[6] = new TradeGood("Firearms", 4, 1, calcSellPrice("Firearms", 725), calcQuantity());//Firearms
				demanded[3] = new TradeGood("Ore", 4, 1, calcSellPrice("Ore", 390), calcQuantity());//Ore
				demanded[8] = new TradeGood("Machines", 4, 1, calcSellPrice("Machines", 690), calcQuantity());//Machines
				demanded[7] = new TradeGood("Robots", 4, 1, calcSellPrice("Robots", 3950), calcQuantity());//Robot
				break;
				
			case 8://hi tech (sell machines/robots cheap. buy natural goods at high price)
				demanded[0] = new TradeGood("Water", 1, 1, calcSellPrice("Water", 30), calcQuantity());//Water
				demanded[1] = new TradeGood("Furs", 2, 1, calcSellPrice("Furs", 250), calcQuantity());//Furs
				demanded[2] = new TradeGood("Food", 3, 1, calcSellPrice("Food", 105), calcQuantity());//Food
				demanded[5] = new TradeGood("Narcotics", 3, 1, calcSellPrice("Narcotics", 2625), calcQuantity());//Narcotics
				demanded[9] = new TradeGood("Games", 4, 1, calcSellPrice("Games", 180), calcQuantity());//Games
				demanded[4] = new TradeGood("Medicine", 2, 1, calcSellPrice("Medicine", 510), calcQuantity());//Medicine
				demanded[6] = new TradeGood("Firearms", 4, 1, calcSellPrice("Firearms", 725), calcQuantity());//Firearms
				demanded[3] = new TradeGood("Ore", 4, 1, calcSellPrice("Ore", 390), calcQuantity());//Ore
				demanded[8] = new TradeGood("Machines", 4, 1, calcSellPrice("Machines", 690), calcQuantity());//Machines
				demanded[7] = new TradeGood("Robots", 4, 1, calcSellPrice("Robots", 3950), calcQuantity());//Robot
				break;
				
			default:
				break;
		}
		return demanded;
	}
	
	/**
	 * Calculates the price a player can sell a trade good based on the planet's tech level, government type, and state
	 * @param String type is the Name of trade good
	 * @param int price is the base cost of the trade good before adjustment
	 * @return integer - final price of a good that appears 
	 */
	public int calcSellPrice(String type, int price){
		
		//Government Type affects price
		switch(govType){
		
			case 1://anarchy (food brings good prices)
				if(type.equals("Food"))
					price = price*2;
				break;
		
			case 2://capitalist (ore in high demand)
				if(type.equals("Ore"))
					price += 150;
				break;
			
			case 3://communist (illegal goods craved)
				if(type.equals("Narcotics"))
					price = (int) Math.round(price*1.5);
				break;
			
			case 4://confederacy (fine price for games)
				if(type.equals("Games"))
					price = (int) Math.round(price*1.7);
				break;
				
			case 5://corporate (robots in high demand)
				if(type.equals("Robots"))
					price = (int) Math.round(price*1.7);
				break;
				
			case 6://cybernetic (ore in high demand)
				if(type.equals("Ore"))
					price = price*2;
				break;
				
			case 7://democracy (games in high demand)
				if(type.equals("Games"))
					price = price*2;
				break;
				
			case 8://dictatorship (...)
				//no change in price
				break;
				
			case 9://fascist (do not buy illegal goods, like machines)
				if(type.equals("Machines"))
					price = (int) Math.round(price*1.5);
				break;
				
			case 10://feudal (good price for firearms)
				if(type.equals("Firearms"))
					price = price*2;
				break;
				
			case 11://military (robots fetch fine price)
				if(type.equals("Robots"))
					price = (int) Math.round(price*1.6);
				break;
				
			case 12://monarchy (medicine in high demand)
				if(type.equals("Medicine"))
					price = (int) Math.round(price*1.5);
				break;
				
			case 13://pacifist (abhor firearms/illegal goods, only buy natural resources)
				//no price change for natural goods
				break;
				
			case 14://socialist (illegal goods thrive)
				if(type.equals("Narcotics")){
					price = (int) Math.round(price*1.3);
				}
				break;
				
			case 15://satori (enlightenment monks)(arent interested in goods)
				//no price change because they don't buy anything
				break;
				
			case 16://technocracy (water highly valued)
				if(type.equals("Water"))
					price = price*3;
				break;
				
			case 17://theocracy (good price for narcotics) How ironic.
				if(type.equals("Naracotics"))
					price = price*2;
				break;
		}
		
		//Some Tech levels affect price
		switch(techLvl){
			
			case 1://pre-agricultural (like narcotics)
				if(type.equals("Narcotics"))
					price += 150;
				break;
			
			case 7://post industrial (rich people, buy natural resources at high price)
				if(type.equals("Water") || type.equals("Furs") || type.equals("Ore") || type.equals("Food"))
					price += 100;
				break;
				
			case 8://hi tech (sell machines/robots cheap. buy natural goods at high price)
				if(type.equals("Water") || type.equals("Furs") || type.equals("Ore") || type.equals("Food"))
					price += 125;
				break;
		}
		
		//Planet States affect price
		
		switch(state){
		
			case 1://drought (water fetches high price)
				if(type.equals("Water"))
					price += 75;
				break;
				
			case 2://war (firearms fetch high price)
				if(type.equals("Firearms"))
					price += 150;
				break;
				
			case 3://normal
				//no price change
				break;
				
			case 4://cold spell (furs fetch high price)
				if(type.equals("Furs"))
					price += 90;
				break;
				
			case 5://crop failure (food fetches high price)
				if(type.equals("Food"))
					price += 100;
				break;
				
			case 6://plague (medicine fetches high price)
				if(type.equals("Medicine"))
					price = (int) Math.round(price*1.3);
				break;
		}
		
		Random rand = new Random();
		price += rand.nextInt(40) - 20;//adds a random number between -20 and 20 to the final price. Adds an element of randomness to the prices on a planet
		
		return price;
	}
	
	/**
	 * Calculates the price a player must pay to buy a trade good from a planet based on planet's state.
	 * @param the base price of a TradeGood before any adjusting for a particular state
	 * @return price a player must pay for a TradeGood
	 */
	public int calcBuyPrice(String type, int price){
		//Planet State Affects Price(war, plague, drought, etc)		
		switch(state){
			case 1://drought (water fetches high price)
				if(type.equals("Water"))
					price += price;//during a drought water is twice as expensive to buy
				break;
			
			case 2://war (firearms fetch high price)
				if(type.equals("Firearms"))
					price += price;//during a war firearms are twice as expensive to buy
				break;
			
			case 3://normal
				//no change from the base price
				break;
				
			case 4://cold spell (furs fetch high price)
				if(type.equals("Furs"))
					price += price;//during a cold spell furs are twice as expensive to buy
				break;
				
			case 5://crop failure (food fetches high price)
				if(type.equals("Food"))
					price += price;//during a crop failure food is twice as expensive to buy
				break;
				
			case 6://plague (medicine fetches high price)
				if(type.equals("Medicine"))
					price += price;//during a plague medicine is twice as expensive to buy	
				break;
		}
		Random rand = new Random();
		price += rand.nextInt(40) - 20;//adds a random number between -20 and 20 to the final price. Adds an element of randomness to the prices on a planet
		
		return price;
	}
	
	/**
	 * Calculates the quantity of a particular TradeGood are up for sale on a planet. Does this by generating a random number between 1 and 5
	 * @return random integer quantity
	 */
	public int calcQuantity(){
		Random rand = new Random();
		return rand.nextInt(4)+1;
	}
	
	/**
	 * Returns an array of trade goods that are exist in the player's cargo that are sellable on a particular planet.
	 * @return TradeGood[] of 
	 */
	public TradeGood[] getPlayerSellables(TradeGood[] shipCargo){
		TradeGood[] sellables = new TradeGood[demanded.length];
		int index = 0;
			
		//Adds items in the players cargo
		for(int i = 0; i < shipCargo.length; i++){
			if(shipCargo[i] != null && demanded != null){
				sellables[index] = shipCargo[i];
				index++;
			}
		}
		return sellables;
	}
	
	public TradeGood[] getMarketDemand(){
		return demanded;
	}//end getter getMarketDemand

	/**
	 * @return the marketMap
	 */
	public HashMap<String, TradeGood> getMarketMap() {
		return marketMap;
	}

	/**
	 * @param marketMap the marketMap to set
	 */
	public void setMarketMap(HashMap<String, TradeGood> marketMap) {
		this.marketMap = marketMap;
	}
	
	/**
	 * Returns a List of TradeGood names. These strings are used as keys for the HashMap of tradeGoods
	 * @return ArrayList<String> of TradeGood names
	 */
	public ArrayList<String> getTradeGoodStrings(){
		return tradeGoodStrings;
	}
	
	/**
	 * toString method
	 * @return String
	 */
	public String toString(){
		String str = null;
		return str;
	}
}
